<?php
class mobanForm extends ClFormModel
{
    public $title;
    public $isshow;
    public $typeid;
    public $logo;
    public $minfo;
    public $morder;
    public $bg;


    //表单验证规则
	public function rules()
	{
		return array(
			array('title,typeid,isshow,bg', 'required'),
			array('logo,minfo,morder','safe'),
		);
	}

	//字段标签
	public function attributeLabels()
	{
		return array(
			'title'=>'标题',
			'typeid'=>'类型',
			'isshow'=>'显示隐藏',
            'logo'=>'图片',
            'minfo'=>'简介',
            'morder'=>'排序',
            'bg'=>"背景"
        );
	}

	//添加
	public function add()
	{
		$game = new moban();

		$game->title=$this->title;
		$game->typeid=$this->typeid;
        $game->isshow=$this->isshow;
        $game->minfo=$this->minfo;
        $game->morder=$this->morder;
        $game->logo=$this->bg;
		$game->author = Yii::app()->session['admin_real_name'];
        $game->logo=$this->logo;


		//发布时间
		$game->addtime=time();
        return $game->save() ? true : false;

	}
	
	//修改
	public function edit($id)
	{
		$game = moban::model()->findByPk($id);
        $game->title=$this->title;
        $game->typeid=$this->typeid;
        $game->isshow=$this->isshow;
        $game->minfo=$this->minfo;
        $game->morder=$this->morder;
        $game->logo=$this->bg;

		 return $game->save() ? true : false;
	}
}